// import axios from 'axios'
import axiosIns from '../api/axiosIns'
// import store from '../store/index'
import { _login } from '../api/storage'
// import * as types from '../store/mutation-types'

export default
function routerPermission (router) {
  axiosIns.interceptors.response.use(response => {
    if (response.data.data.message === '未登陆') {
      window.localStorage.hasLogin = 200
      setTimeout(() => {
        router.replace({
          path: '/login'
        })
      }, 0)
      return response
    } else {
      return response
    }
  }, error => {
    return Promise.reject(error)
  })
  const wls = window.localStorage
  router.beforeEach((to, form, next) => {
    window.scrollTo(0, 0)
    if (wls && wls.hasLogin !== _login) {
      wls.hasLogin = 200
      setTimeout(() => {
        router.replace({
          path: '/login'
        }, 0)
      })
      return next()
    }
    return next()
  })
}
